package cn.ctyun.ipush.web.user.dao;

import cn.ctyun.ipush.web.user.bo.UserModel;
import com.dexcoder.dal.JdbcDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: user
 * Date: 16-6-29
 * Time: 下午4:58
 * To change this template use File | Settings | File Templates.
 */
@Component
public class UserDao {
    @Autowired
    private JdbcDao jdbcDao;

    public UserModel checkIsExist(String systemUser,String userPassword){
        UserModel userModel =new UserModel();
        userModel.setUserLoginName(systemUser);
        userModel.setUserPassword(userPassword);
        userModel =jdbcDao.querySingleResult(userModel);
        if(null!= userModel){
            return userModel;
        }else{
            return null;
        }
    }
    public List<UserModel> listAll(UserModel userModel){
        List userList=jdbcDao.queryList(userModel);
        if(null!=userList){
            return userList;
        }else{
            return null;
        }
    }

    public boolean save(UserModel userModel){
        try{
            jdbcDao.save(userModel);
            return true;
        }catch (Exception e){
            return  false;
        }
    }
    public  boolean delete(UserModel userModel){
        try{

            jdbcDao.delete(userModel);
            return true;
        }catch (Exception e){
            return  false;
        }
    }
    public  boolean update(UserModel userModel){
        try{

            jdbcDao.update(userModel);
            return true;
        }catch (Exception e){
            return  false;
        }
    }
    public UserModel getUserById(String uid){
        UserModel userModel = new UserModel();
        userModel.setUserModelId(uid);
        return jdbcDao.querySingleResult(userModel);
    }

}
